<?php



/**
 * Skeleton subclass for representing a row from the 'users' table.
 *
 *
 *
 * You should add additional methods to this class to meet the
 * application requirements.  This class will only be generated as
 * long as it does not already exist in the output directory.
 *
 * @package    propel.generator.empeval
 */
class EmpevalUsers extends EmpevalBaseUsers
{	
	
	public function isHr() {
		foreach ($this->getUserRolessRelatedByToUserId() as $userRoles) {
			if ($userRoles->getRoles()->getCode() == EmpevalRoles::CODE_HR)
				return true;
		}
		return false;
	}
	
	public function isAdmin() {
		foreach ($this->getUserRolessRelatedByToUserId() as $userRoles) {
			if ($userRoles->getRoles()->getCode() == EmpevalRoles::CODE_ADMIN)
				return true;
		}
		return false;
	}
	
	public function generatePassword($length = 8) {
		$password = "";
		$possible = "12346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
		$maxlength = strlen($possible);
		if ($length > $maxlength) {
			$length = $maxlength;
		}
		$i = 0;
		while ($i < $length) {
			$char = substr($possible, mt_rand(0, $maxlength - 1), 1);
			if (!strstr($password, $char)) {
				$password .= $char;
				$i++;
			}
		}
		$this->setPassword(hash('sha256', $password));
		return $password;
	}
	
}
